package com.wuuxiang.polestar.admin.dao;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.springframework.beans.factory.annotation.Value;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.Serializable;

/**
 * 项目名称：polestar        <br>
 * 类描述：                         <br>
 * 创建人：夏鸿鹏                    <br>
 * 创建时间：2017-11-28 10:36        <br>
 * 修改备注：                        <br>
 */

public class BaseDao implements Serializable {
    private static final long serialVersionUID = 1L;

    // zk地址
    @Value("${zookeeper.address}")
    private String zkAddress;
    // zk客户端
    private CuratorFramework client;

    @PostConstruct
    private void init() {
        client = CuratorFrameworkFactory.newClient(zkAddress, new ExponentialBackoffRetry(1000, 3));
        client.start();
    }

    @PreDestroy
    private void destroy() {
        if (client != null) {
            client.close();
        }
    }

    public CuratorFramework getClient() {
        return client;
    }

}
